package com.boatAnchorAssistant.service.listener;

import com.boatAnchorAssistant.pojo.dto.expandValue.UpdateExpandValueDto;
import com.boatAnchorAssistant.pojo.event.user.CreateUserEvent;
import com.boatAnchorAssistant.pojo.event.user.EditUserEvent;
import com.boatAnchorAssistant.service.service.in.ExpandValueService;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

/**
 * 【描 述】：
 * 【环 境】：J2SE 17
 * 【详 细】：
 *
 * @author 李松林
 * @version v1.0 2024/6/11 新建
 * @since 2024/6/11
 */
@Service
public class ExpandValueListener {

    private final ExpandValueService service;

    public ExpandValueListener(ExpandValueService service) {
        this.service = service;
    }


    /**
     * 创建用户
     * @param event
     */
    @EventListener(CreateUserEvent.class)
    public void createUserEvent(CreateUserEvent event){
        UpdateExpandValueDto dto = new UpdateExpandValueDto();
        BeanUtils.copyProperties(event,dto);
        service.updateExpandValue(dto);
    }


    /**
     * 编辑用户
     * @param event
     */
    @EventListener(EditUserEvent.class)
    public void editUserEvent(EditUserEvent event){
        UpdateExpandValueDto dto = new UpdateExpandValueDto();
        BeanUtils.copyProperties(event,dto);
        service.updateExpandValue(dto);
    }


}
